package com.linzm.creationaltype.abstractfactory02;

import com.linzm.creationaltype.abstractfactory02.Color.Color;
import com.linzm.creationaltype.abstractfactory02.Shape.Shape;
import com.linzm.creationaltype.abstractfactory02.factory.AbstractFactory;
import com.linzm.creationaltype.abstractfactory02.factory.FactoryProducer;

import static com.linzm.creationaltype.abstractfactory02.enums.FactoryTypeEnum.COLOR_FACTORY;
import static com.linzm.creationaltype.abstractfactory02.enums.FactoryTypeEnum.SHAPE_FACTORY;
import static com.linzm.creationaltype.abstractfactory02.enums.ShapeTypeEnum.CIRCLE;
import static com.linzm.creationaltype.abstractfactory02.enums.ShapeTypeEnum.RECTANGLE;
import static com.linzm.creationaltype.abstractfactory02.enums.ShapeTypeEnum.SQUARE;
import static com.linzm.creationaltype.abstractfactory02.enums.ColorTypeEnum.RED;
import static com.linzm.creationaltype.abstractfactory02.enums.ColorTypeEnum.GREEN;
import static com.linzm.creationaltype.abstractfactory02.enums.ColorTypeEnum.BLUE;

/**
 * @Author zimingl
 * @Date 2023/4/15 19:45
 * @Description: AbstractFactoryPatternDemo
 */
public class AbstractFactoryPatternDemo {
    public static void main(String[] args) throws Exception {
        //获取形状工厂
        AbstractFactory shapeFactory = FactoryProducer.getFactory(SHAPE_FACTORY.name());

        //获取形状为 Circle 的对象
        Shape shape1 = shapeFactory.getShape(CIRCLE.name());
        //调用 Circle 的 draw 方法
        shape1.draw();

        //获取形状为 Rectangle 的对象
        Shape shape2 = shapeFactory.getShape(RECTANGLE.name());
        //调用 Rectangle 的 draw 方法
        shape2.draw();

        //获取形状为 Square 的对象
        Shape shape3 = shapeFactory.getShape(SQUARE.name());
        //调用 Square 的 draw 方法
        shape3.draw();

        //获取颜色工厂
        AbstractFactory colorFactory = FactoryProducer.getFactory(COLOR_FACTORY.name());

        //获取颜色为 Red 的对象
        Color color1 = colorFactory.getColor(RED.name());
        //调用 Red 的 fill 方法
        color1.fill();

        //获取颜色为 Green 的对象
        Color color2 = colorFactory.getColor(GREEN.name());
        //调用 Green 的 fill 方法
        color2.fill();

        //获取颜色为 Blue 的对象
        Color color3 = colorFactory.getColor(BLUE.name());
        //调用 Blue 的 fill 方法
        color3.fill();
    }
}
